2020-2021 Sunseeker Telemetry and Lighting System
gpio_ex2_inputCapture.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // Software Port Interrupt Service on P1.4 from LPM4 with
34 // Internal Pull-up Resistance Enabled
35 //
36 // A hi "TO" low transition on P1.4 will trigger P1_ISR which,
37 // toggles P1.0. P1.4 is internally enabled to pull-up. Normal mode is
38 // LPM4 ~ 0.1uA. LPM4 current can be measured with the LED removed, all
39 // unused Px.x configured as output or inputs pulled high or low.
40 // ACLK = n/a, MCLK = SMCLK = default DCO
41 //
42 // Tested On: MSP430F5529, MSP430FR5739
43 // -----------------
44 // /|\| XIN|-
45 // | | |
46 // --|RST XOUT|-
47 // /|\ | |
48 // --o--|P1.4 P1.0|-->LED
49 // \|/
50 //
51 // This example uses the following peripherals and I/O signals. You must
52 // review these and change as needed for your own board:
53 // - GPIO Port peripheral
54 //
55 // This example uses the following interrupt handlers. To use this example
56 // in your own application you must add these interrupt handlers to your
57 // vector table.
58 // - PORT1_VECTOR
59 //******************************************************************************
60 #include "driverlib.h"
61 
62 void main (void)
63 {
64  //Stop watchdog timer
65  WDT_A_hold(WDT_A_BASE);
66 
67  //Set P1.0 to output direction
68  GPIO_setAsOutputPin(
69  GPIO_PORT_P1,
70  GPIO_PIN0
71  );
72 
73  //Enable P1.4 internal resistance as pull-Up resistance
74  GPIO_setAsInputPinWithPullUpResistor(
75  GPIO_PORT_P1,
76  GPIO_PIN4
77  );
78 
79  //P1.4 interrupt enabled
80  GPIO_enableInterrupt(
81  GPIO_PORT_P1,
82  GPIO_PIN4
83  );
84 
85  //P1.4 Hi/Lo edge
86  GPIO_selectInterruptEdge(
87  GPIO_PORT_P1,
88  GPIO_PIN4,
89  GPIO_HIGH_TO_LOW_TRANSITION
90  );
91 
92 
93  //P1.4 IFG cleared
94  GPIO_clearInterrupt(
95  GPIO_PORT_P1,
96  GPIO_PIN4
97  );
98 
99  //Enter LPM4 w/interrupt
100  __bis_SR_register(LPM4_bits + GIE);
101 
102  //For debugger
103  __no_operation();
104 }
105 
106 //******************************************************************************
107 //
108 //This is the PORT1_VECTOR interrupt vector service routine
109 //
110 //******************************************************************************
111 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
112 #pragma vector=PORT1_VECTOR
113 __interrupt
114 #elif defined(__GNUC__)
115 __attribute__((interrupt(PORT1_VECTOR)))
116 #endif
117 void Port_1 (void)
118 {
119  //P1.0 = toggle
120  GPIO_toggleOutputOnPin(
121  GPIO_PORT_P1,
122  GPIO_PIN0
123  );
124 
125 
126  //P1.4 IFG cleared
127  GPIO_clearInterrupt(
128  GPIO_PORT_P1,
129  GPIO_PIN4
130  );
131 }
132 
void Port_1(void)
void main(void)
__no_operation()